<template>
	<el-dialog title="审批" v-model="visible" :close-on-click-modal="false" draggable>
		<el-form ref="dataFormRef" :model="form" :rules="dataRules" formDialogRef label-width="90px" v-loading="loading">
			<el-row :gutter="24">
				<el-col :span="12" class="mb20">
					<el-form-item label="请假类型" prop="leaveType">
						<el-select disabled v-model="form.leaveType" placeholder="请选择请假类型">
							<el-option :value="item.value" :label="item.label" v-for="(item, index) in leave_type" :key="index"></el-option>
						</el-select>
					</el-form-item>
				</el-col>

				<el-col :span="12" class="mb20">
					<el-form-item label="开始日期" prop="startDate">
						<el-date-picker disabled type="date" placeholder="请选择开始日期" v-model="form.startDate" :value-format="dateStr"></el-date-picker>
					</el-form-item>
				</el-col>

				<el-col :span="12" class="mb20">
					<el-form-item label="起始时间" prop="startDatePart">
						<el-select disabled v-model="form.startDatePart" placeholder="请选择起始时间">
							<el-option :value="item.value" :label="item.label" v-for="(item, index) in day_part" :key="index"></el-option>
						</el-select>
					</el-form-item>
				</el-col>

				<el-col :span="12" class="mb20">
					<el-form-item label="结束日期" prop="endDate">
						<el-date-picker disabled type="date" placeholder="请选择结束日期" v-model="form.endDate" :value-format="dateStr"></el-date-picker>
					</el-form-item>
				</el-col>

				<el-col :span="12" class="mb20">
					<el-form-item label="结束时间" prop="endDatePart">
						<el-select disabled v-model="form.endDatePart" placeholder="请选择结束时间">
							<el-option :value="item.value" :label="item.label" v-for="(item, index) in day_part" :key="index"></el-option>
						</el-select>
					</el-form-item>
				</el-col>

				<el-col :span="12" class="mb20">
					<el-form-item label="天数" prop="days">
						<el-input disabled v-model="form.days" placeholder="请输入天数" />
					</el-form-item>
				</el-col>

				<el-col :span="12" class="mb20">
					<el-form-item label="请假理由" prop="reason">
						<el-input disabled type="textarea" v-model="form.reason" placeholder="请输入请假理由" />
					</el-form-item>
				</el-col>

				<el-col :span="24" class="mb20">
					<el-form-item label="审批意见" prop="attitude">
						<el-input type="textarea" v-model="form.attitude" placeholder="请输入审批意见" />
					</el-form-item>
				</el-col>
			</el-row>
		</el-form>
		<template #footer>
			<span class="dialog-footer">
				<el-button type="warning" @click="disAgree()" :disabled="loading">驳回</el-button>
				<el-button type="primary" @click="agree()" :disabled="loading">通过</el-button>
			</span>
		</template>
	</el-dialog>
</template>

<script setup lang="ts" name="AskForLeaveDialog">
import { useDict } from '@/hooks/dict';
import { useMessage } from '@/hooks/message';
import { getObj, approve, putObj } from '@/api/oa/approval';
import { rule } from '@/utils/validate';

const emit = defineEmits(['refresh']);

// 定义变量内容
const dataFormRef = ref();
const visible = ref(false);
const loading = ref(false);
// 定义字典
const { leave_type, day_part } = useDict('leave_type', 'day_part');

function generateForm() {
	return {
		id: '',
		taskId: '',
		leaveType: '',
		startDate: '',
		startDatePart: '',
		endDate: '',
		endDatePart: '',
		days: '',
		reason: '',
		userId: '',
		attitude: '',
	};
}

// 提交表单数据
const form = ref(generateForm());

// 定义校验规则
const dataRules = ref({
	/*  leaveType: [{required: true, message: '请假类型不能为空', trigger: 'blur'}],
  startDate: [{required: true, message: '开始日期不能为空', trigger: 'blur'}],
  startDatePart: [{required: true, message: '起始时间不能为空', trigger: 'blur'}],
  endDate: [{required: true, message: '结束日期不能为空', trigger: 'blur'}],
  endDatePart: [{required: true, message: '结束时间不能为空', trigger: 'blur'}],
  days: [{required: true, message: '天数不能为空', trigger: 'blur'}],
  reason: [{required: true, message: '请假理由不能为空', trigger: 'blur'}],*/
});

// 打开弹窗
const openDialog = (id: string) => {
	visible.value = true;
	form.value.id = '';

	// 重置表单数据
	nextTick(() => {
		dataFormRef.value?.resetFields();
	});

	// 获取askForLeave信息
	if (id) {
		form.value.id = id;
		//getaskForLeaveData(id);
	}
};

// 提交
const agree = async () => {
	approve(form.value).then(() => {
		emit('refresh');
		visible.value = false;
	});
};
const disAgree = async () => {};

// 暴露变量
defineExpose({
	openDialog,
});
</script>
